<%@ page import="com.domain.User" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <meta charset="utf-8">
    <title>留言</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/AdminLTE.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/pagination.css">
    <script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap.js"></script>
    <script src="${pageContext.request.contextPath}/js/pagination.js"></script>
    <script src="${pageContext.request.contextPath}/js/my.js"></script>
</head>

<body class="hold-transition skin-red sidebar-mini">
<%
     User user= (User) request.getSession().getAttribute("USER_SESSION");
%>
<!-- .box-body -->
<div class="box-header with-border">
    <h3 class="box-title">留言！</h3>
</div>
<div class="box-body">
    <%--新增按钮：如果当前登录用户是管理员，页面展示新增按钮--%>
    <c:if test="${USER_SESSION.role =='USER'}">
        <div class="pull-left">
            <div class="form-group form-inline">
                <div class="btn-group">
                    <button type="button" class="btn btn-default" title="新建" data-toggle="modal"
                            data-target="#addOrEditModal" onclick="findUserById(${USER_SESSION.id})"> 我要留言
                    </button>
                </div>
            </div>
        </div>
    </c:if>
    <div class="table-box">
        <!-- 数据表格 -->
        <table id="dataList" class="table table-bordered table-striped table-hover dataTable text-center">
            <thead>
            <tr>
                <th class="sorting_asc">建议类型</th>
                <th class="sorting"></th>
                <th class="sorting"></th>
                <th class="sorting">建议内容</th>
                <th class="sorting"></th>
                <th class="sorting">发表时间</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${pageResult.rows}" var="message">
                <tr>
                    <td> ${message.messagesort}</td>
                    <td></td>
                    <td></td>
                    <td>${message.messagecontent}</td>
                    <td>${message.username}</td>
                    <td>${message.messagedate}</td>
                    <td></td>
                    <td class="text-center">
                        <c:if test="${USER_SESSION.id == message.userid || USER_SESSION.role == 'ADMIN'}">
                            <button type="button" class="btn bg-olive btn-xs" onclick="delMessage(${message.id})">删除</button>
                        </c:if>

                    </td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
        <!--数据表格/-->
        <%--分页插件--%>
        <div id="pagination" class="pagination"></div>
    </div>
    <!--数据列表/-->
</div>

<!-- 添加和编辑图书的模态窗口 -->
<div class="modal fade" id="addOrEditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h3 id="myModalLabel">读者留言</h3>
            </div>
            <div class="modal-body">
                <form id="addOrEditMessage">
                    <span><input type="hidden" id="uid" name="userid"></span>
                    <table id="addOrEditTab" class="table table-bordered table-striped" width="800px">
                        <%--图书的id,不展示在页面--%>
                            <td>建议分类</td>
                            <td>
                                <select class="form-control" name="messagesort"id="emmessagesort">
                                    <option value="环境相关">环境相关</option>
                                    <option value="设备相关">设备相关</option>
                                    <option value="人员相关">人员相关</option>
                                    <option value="书籍相关">书籍相关</option>
                                    <option value="其他">其他</option>
                                </select>
                            </td>
                            <td>建议内容</td>
                            <td><input class="form-control" placeholder="留言内容" name="messagecontent" id="emmessagecontent"></td>
                        </tr>
                    </table>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-success" data-dismiss="modal" aria-hidden="true"  onclick="addOrEditMessage()">保存
                </button>
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
            </div>
        </div>
    </div>
</div>

</body>
<script>
    /*分页插件展示的总页数*/
    pageargs.total = Math.ceil(${pageResult.total}/pageargs.pagesize);
    /*分页插件当前的页码*/
    pageargs.cur = ${pageNum}
        /*分页插件页码变化时将跳转到的服务器端的路径*/
        pageargs.gourl = "${gourl}"
    /*保存搜索框中的搜索条件，页码变化时携带之前的搜索条件*/
    bookVO.name = "${search.name}"
    bookVO.author = "${search.author}"
    bookVO.press = "${search.press}"
    /*分页效果*/
   pagination(pageargs);
<%--document.getElementById("emuserid").value=("${sessionScope.USER_SESSION.name}")--%>
</script>
</html>